<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      margin: 0;
    }
    #father {
      /* position: relative; */
      margin: 200px;
      width: 200px;
      height: 200px;
      border: 1px solid #ccc;
      padding: 50px 100px;
    }
    #son {
      width: 50px;
      height: 50px;
      border: 10px solid red;
      background-color: pink;
    }
  </style>
</head>
<body>
  <div id="father">
    <div id="son"></div>
  </div>
  <script>
    var father = document.querySelector('#father')
    var son = document.querySelector('#son')

    console.log( father.offsetLeft )  // 距离左边距离
    console.log( son.offsetLeft )

    console.log( father.offsetTop )  // 距离顶部距离
    console.log( son.offsetTop )

    console.log(222,  father.offsetWidth )  // width + 2 *padding + 2 *border
    console.log( son.offsetWidth )

    console.log( father.offsetHeight)
    console.log( son.offsetHeight )

    console.log( son.offsetParent )  // 找到距离最近的定位的父节点
  </script>
</body>
</html>